//
//  LSCupScheduleCell.m
//  LookScore
//
//  Created by nice on 2018/6/26.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSCupScheduleCell.h"
#import "LSCupIntegralModel.h"
@interface LSCupScheduleCell()
@property (nonatomic,strong) UILabel *timelable;
@property (nonatomic,strong) UILabel *homeTeam;
@property (nonatomic,strong) UILabel *scorelable;
@property (nonatomic,strong) UILabel *guestTeam;
@end
@implementation LSCupScheduleCell



+(LSCupScheduleCell *)cupScheduleCellByTableView:(UITableView *)tableView{
    LSCupScheduleCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell = [[LSCupScheduleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContentView];
    }
    
    return self;
}
- (void)addContentView{
    
    self.timelable.text = @"2017/11/04 08:30";
    [self.contentView addSubview:self.timelable];
    self.timelable.sd_layout
    .leftEqualToView(self.contentView).offset(LSAutoVlaue(10, LSScreenWidth))
    .centerYEqualToView(self.contentView)
    .heightIs(LSAutoVlaue(35, LSScreenHeight));
    [self.timelable setSingleLineAutoResizeWithMaxWidth:180];
    self.guestTeam.text = @"皇家马德里";
    [self.contentView addSubview:self.guestTeam];
    self.guestTeam.sd_layout
    .rightSpaceToView(self.contentView, LSAutoVlaue(10, LSScreenWidth))
    .centerYEqualToView(self.contentView)
    .widthIs(LSAutoVlaue(80, LSScreenWidth))
    .heightIs(LSAutoVlaue(35, LSScreenHeight));
    
    self.scorelable.text = @"1:1";
    [self.contentView addSubview:self.scorelable];
    self.scorelable.sd_layout
    .rightSpaceToView(self.guestTeam, LSAutoVlaue(10, LSScreenWidth))
    .centerYEqualToView(self.contentView)
    .widthIs(LSAutoVlaue(30, LSScreenWidth))
    .heightIs(LSAutoVlaue(35, LSScreenWidth));
    
    
    self.homeTeam.text = @"巴萨罗那";
    [self.contentView addSubview:self.homeTeam];
    self.homeTeam.sd_layout
    .rightSpaceToView(self.scorelable, LSAutoVlaue(10, LSScreenWidth))
    .centerYEqualToView(self.contentView)
    .widthIs(LSAutoVlaue(80, LSScreenWidth))
    .heightIs(LSAutoVlaue(35, LSScreenHeight));
    
   
    
    
    
}
- (UILabel *)timelable{
    if (!_timelable) {
        _timelable = [[UILabel alloc] init];
        _timelable.textAlignment = NSTextAlignmentCenter;
        _timelable.textColor = LSTitleGrayColor2;
        _timelable.font = LSFontSize(13,LSScreenWidth);
    }
    return _timelable;
}
- (UILabel *)homeTeam{
    if (!_homeTeam) {
        _homeTeam = [[UILabel alloc] init];
        _homeTeam.textAlignment = NSTextAlignmentCenter;
        _homeTeam.textColor = LSTitleGrayColor2;
        _homeTeam.font = LSFontSize(13,LSScreenWidth);
    }
    return _homeTeam;
}
- (UILabel *)scorelable{
    if (!_scorelable) {
        _scorelable = [[UILabel alloc] init];
        _scorelable.textAlignment = NSTextAlignmentCenter;
        _scorelable.textColor = LSTitleGrayColor2;
        _scorelable.font = LSFontSize(13,LSScreenWidth);
    }
    return _scorelable;
}
- (UILabel *)guestTeam{
    if (!_guestTeam) {
        _guestTeam = [[UILabel alloc] init];
        _guestTeam.textAlignment = NSTextAlignmentCenter;
        _guestTeam.textColor = LSTitleGrayColor2;
        _guestTeam.font = LSFontSize(13,LSScreenWidth);
    }
    return _guestTeam;
}

- (void)setModel:(data *)model{
    _model = model;
    
    self.timelable.text = [CommonClass timesTampMaxToString:model.TimeStamp];;
    self.homeTeam.text = model.HomeTeamName;
    self.guestTeam.text  = model.GuestTeamName;
    
    if ([CommonClass isBlankString:model.TeamScore]) {
        self.scorelable.text = @"- -";
    }else{
        self.scorelable.text = model.TeamScore;
    }
    
}

@end

@interface LSCupIntergralCell()
@property (nonatomic, strong) NSMutableArray * labelArray;
@property (nonatomic, strong) UIImageView * iconImageView;
@property (nonatomic, strong) UIImageView * teamImageView;
@property (nonatomic, strong) UILabel * teamNameLabel;

@property (nonatomic, strong) UILabel * rankLabel;
@end

@implementation LSCupIntergralCell
- (NSMutableArray *)labelArray{
    if (!_labelArray) {
        _labelArray = @[].mutableCopy;
    }
    return _labelArray;
}
+ (LSCupIntergralCell *)cupIntergralCellByTableView:(UITableView *)tableView{
    LSCupIntergralCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell = [[LSCupIntergralCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle =  UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self addContentView];
    }
    return self;
}

- (void)addContentView{
    
    float weight = LSScreenWidth/10;
    
    for (NSInteger i = 0; i<6; i++) {
        UILabel * label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:LSScareValue(13, LSScreenWidth)];
        label.textColor = RGB(93,93,93);
        label.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:label];
        [self.labelArray addObject:label];
        label.sd_layout
        .rightSpaceToView(self.contentView, i*weight)
        .centerYEqualToView(self.contentView)
        .widthIs(weight)
        .autoHeightRatio(0);
        
    }
    _iconImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_iconImageView];
    _iconImageView.sd_layout
    .leftSpaceToView(self.contentView, 17)
    .centerYEqualToView(self.contentView)
    .widthIs(12)
    .heightIs(13);
    _rankLabel = [[UILabel alloc] init];
    _rankLabel.textAlignment = NSTextAlignmentCenter;
    _rankLabel.font = LSFontSize(14, LSScreenWidth);
    _rankLabel.textColor = RGB(93,93,93);
    _rankLabel.hidden = YES;
    [self.contentView addSubview:_rankLabel];
    _rankLabel.sd_layout
    .leftSpaceToView(self.contentView, 17)
    .centerYEqualToView(self.contentView)
    .widthIs(12)
    .heightIs(13);
    
    _teamImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_teamImageView];
    _teamImageView.sd_layout
    .leftSpaceToView(_iconImageView, LSScreenWidth/11)
    .centerYEqualToView(self.contentView)
    .widthIs(20)
    .heightIs(20);
    
    
    
    _teamNameLabel = [[UILabel alloc] init];
    _teamNameLabel.textColor = RGB(93,93,93);
    _teamNameLabel.numberOfLines = 2;
    _teamNameLabel.font = [UIFont systemFontOfSize:LSScareValue(13, LSScreenWidth)];
//    _teamImageView.
    [self.contentView addSubview:_teamNameLabel];
    _teamNameLabel.sd_layout
    .leftSpaceToView(_teamImageView, 3)
    .centerYEqualToView(self.contentView)
    .autoHeightRatio(0)
    .widthIs(LSScreenWidth/5);
//    [_teamNameLabel setSingleLineAutoResizeWithMaxWidth:180];
    
}

- (void)configDataWithModel:(subIntergralList *)model withIndexRow:(NSInteger)indexRow with:(NSArray *)imageArray{
    _model = model;
    NSArray * array = @[model.TeamIntegralNum,[NSString stringWithFormat:@"%@/%@",model.TeamGet,model.TeamLose],model.TeamLossScreenings,model.TeamFlatScreenings,model.TeamWinScreenings,model.TeamCountScreenings];
    [self.labelArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UILabel * label = obj;
        label.text = array[idx];
        if (idx == 0) {
            label.textColor = [UIColor redColor];
        }
    }];
    [_teamImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",TeamImageHeaderUrl(model.TeamId)]] placeholderImage:nil];
    SDWebImageManager * manger = [[SDWebImageManager alloc] init];
    [manger loadImageWithURL:[NSURL URLWithString:TeamImageHeaderUrl(model.TeamId)] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
        
    } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
        
    }];
    _teamNameLabel.text = model.TeamName;
    
    _rankLabel.text = [NSString stringWithFormat:@"%ld",indexRow];
    if (indexRow<3) {
        self.iconImageView.hidden = NO;
        _rankLabel.hidden = YES;
        self.iconImageView.image = [UIImage imageNamed:imageArray[indexRow]];
    }else{
        _rankLabel.hidden = NO;
        self.iconImageView.hidden = YES;
    }
    
}

- (void)setModel:(subIntergralList *)model{
    _model = model;
    
}
- (NSMutableAttributedString *)AttributedStringWithContent:(NSString *)content WithImage:(UIImage *)image{
    // 富文本技术：
    // 1.图文混排
    // 2.随意修改文字样式
    
    //拿到整体的字符串
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:content];
    
    // 设置 name 颜色，也可以设置字体大小等
//    [string addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#576b95"] range:NSMakeRange(0, name.length)];
    
    
    // 创建图片图片附件
    NSTextAttachment *attach = [[NSTextAttachment alloc] init];
    NSAttributedString *attachString = [NSAttributedString attributedStringWithAttachment:attach];
    attach.image = image;
    attach.bounds = CGRectMake(0, 0, 20, 20);
    //将图片插入到合适的位置
    [string insertAttributedString:attachString atIndex:0];

  
    
    return string;
    
}

@end
